<?php

namespace App\Http\Middleware;

use Closure;

class AdminMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
//        首先判断访问后台是用户是否登录，如果未登录则返回到登录界面进行登录
//        用自定义的守卫进行验证
        if (!\Auth::guard('admin')->check()){
            return redirect()->route('admin.login')->with('error','未登录，无法访问后台');
        }
        return $next($request);
    }
}
